import {
  wxRequest
} from '../../../utils/server.js';
const _wxRequest = new wxRequest();
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: app.globalData.imgUrl,
    uploadUrl: wx.getStorageSync('uploadUrl'),
    pageNo: 1,
    list: [],
    hasNextPage: false,
    keyword: '',
    pageData: {},
    statusList: [{
        id: '',
        text: "全部"
      },
      {
        id: 0,
        text: "待审核"
      },
      {
        id: 1,
        text: "审核通过"
      },
      {
        id: 2,
        text: "审核驳回"
      }
    ],
    auditStatus: ''
  },
  onLoad: function () {
    this.getlist()
  },
  onShow: function () {
    // this.getlist()
  },

  //查询列表
  getlist: function () {
    var url = '/odr/protected/account/findList'
    let params = {
      keyword: this.data.keyword,
      pageNo: this.data.pageNo,
      pageSize: 10
    }
    if (this.data.auditStatus !== '') {
      params.auditStatus = this.data.auditStatus
    }
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + url,
      method: 'POST',
      data: params
    }, (res) => {
      let list = res.list;
      if (this.data.pageNo !== 1) {
        list = this.data.list.concat(list);
      }

      this.setData({
        list: list,
        pageData: res.page,
        pageNo: res.page.pageNo,
        hasNextPage: res.page.hasNextPage,
      });

      console.log(res)

    })
  },

  copyContent(e) {
    const cpoyContent = e.currentTarget.dataset.content;
    wx.setClipboardData({
      //去找上面的数据
      data: cpoyContent,
      success: function (res) {
        wx.showToast({
          title: '已复制详细地址',
        });
      }
    });
  },


  //下拉刷新
  onPullDownRefresh: function () {
    this.refreshData();
    wx.stopPullDownRefresh()
  },

  refreshData: function () {
    this.setData({
      pageNo: 1
    })
    this.getlist();
  },

  //触底时，加载更多
  onReachBottom: function () {
    if (this.data.hasNextPage) {
      this.setData({
        pageNo: this.data.pageNo + 1
      });
      this.getlist();
    }
  },

  //搜索关键词
  seachInputConfirm: function (e) {
    this.setData({
      pageNo: 1,
      keyword: e.detail.value
    })
    this.getlist();
  },

  seachBtn: function () {
    this.setData({
      pageNo: 1,
      keyword: this.data.keyword
    })
    this.getlist();
  },

  seachInputVal: function (e) {
    var inputval = e.detail.value;
    console.log(e)
    this.setData({
      keyword: inputval
    })
  },

  //清空
  clearInput: function () {
    this.setData({
      keyword: ''
    })
    this.getlist();
  },



  // 去审核
  handleAudit: function (e) {
    var item = e.currentTarget.dataset.item
    wx.setStorageSync('auditItem', item)
    wx.navigateTo({
      url: '/pages/finance_account/account_audit/audit_info/audit_info',
    })
  },

  // 查看流水
  toAccountStatement: function (e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/finance_account/account_audit/account_statement/account_statement?id=' + id,
    })
  },

  toWithdrawStatement: function (e) {
    console.log(e);
    let item = e.currentTarget.dataset.item
    wx.showModal({
      title: '要撤回审核吗？',
      success: () => {
        let params = {
          ...item,
          auditStatus: 3
        }
        let url = '/odr/protected/comm/beanCrud/fin.AccountVO/update'
        _wxRequest.wxTonkenAjax({
          url: app.globalData.apiUrl + url,
          method: 'POST',
          data: params
        }, (res) => {
          console.log('审核结果：', res)

          wx.showToast({ title: '撤回成功' })
          setTimeout(() => {
            wx.redirectTo({
              url: '/pages/finance_account/account_audit/account_audit',
            })
          }, 1000)
        })
      }
    })
  },




  //********************筛选更多********************
  popupRight: function () {
    this.setData({
      showPopup: true
    })
  },

  popupCancel: function () {
    this.setData({
      showPopup: false
    })
  },
  //重置
  popupReset: function () {
    this.setData({
      auditStatus: ''
    })
  },

  popupConfirm: function () {
    this.setData({
      pageNo: 1
    })
    this.getlist();
    this.popupCancel();
  },
  //选择状态
  checkStatus: function (e) {
    var auditStatus = e.currentTarget.dataset.id
    this.setData({
      auditStatus
    })
  },
  //********************筛选更多end********************//


})